/**
 * 
 */
package club.zhcs.captrue.utils;

import org.apache.velocity.tools.config.DefaultKey;
import org.apache.velocity.tools.config.InvalidScope;
import org.nutz.lang.Strings;
import org.nutz.mvc.Mvcs;

import com.dgj.utils.common.Numbers;

/**
 * @author xiaoshan 2015年6月10日 下午4:01:43
 */
@DefaultKey("G")
@InvalidScope({ "application" })
public class GlobalUtils {

	public static boolean isNUll(Object o) {
		return o == null;
	}

	public static boolean isDebug() {
		return Strings.equalsIgnoreCase(Mvcs.getReq().getServerName(), "localhost") || Strings.equalsIgnoreCase(Mvcs.getReq().getServerName(), "127.0.0.1");
	}

	public static boolean isBlank(Object o) {
		return o == null || Strings.isBlank(o.toString());
	}

	public static String truncation(double d, int length) {
		return Numbers.format(d, length);
	}

	public static String truncation(String d, int length) {
		return Numbers.format(d, length);
	}

	public static String truncation(Object d, int length) {
		return Numbers.format(d.toString(), length);
	}

	/**
	 * 
	 * @param source
	 * @param key
	 * @return
	 */
	public static boolean startWith(String source, Object key) {
		return source.startsWith(key.toString());
	}
}
